﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HZ.Public;

namespace WpfAppDemo
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
            datagrid.ItemsSource = PublicClass.protocolPlugList;
        }

        public CloseWinType DoBeforeCloseWin()
        {
            foreach (ProtocolPlugClass plug in PublicClass.protocolPlugList)
            {
                if (plug.bProtocolEnable)
                {
                    if (!plug.bRun)
                        plug.LoopExecution();
                }
                else
                {
                    if (plug.bRun)
                        plug.CloseLoopExecution();
                }
            }

            PublicClass.SaveSerializeObject(PublicClass.InfoDir + "protocol.json", PublicClass.protocolPlugList);
            return CloseWinType.Close;
        }

        private void Btn_Set_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            ProtocolPlugClass plug = btn.DataContext as ProtocolPlugClass;
            plug.OpenSetting();
        }
    }
}
